<?php
$this->breadcrumbs = array(
	'All Users' => array('users/index'),
	$user->name => array('users/view', 'id' => $user->id),
	'Edit User'
);
?>
<script type="text/javascript">
	var userId = <?php echo $user->id; ?>;
	var selectedOverride;
</script>
<?php $this->renderPartial('_tabs', array('user' => $user)); ?>
<?php
$form = $this->beginWidget('CActiveForm', array(
	'id' => 'user-form',
	'enableAjaxValidation' => FALSE,
	'htmlOptions' => array(
		'enctype' => 'multipart/form-data',
	)
		));
?>
<div class="grid_10">
	<div id="edit-profile" class="section">
		<div class="block">
			<h2>
				<img src="/images/icons/farmfresh/32x32/book.png" />
				Account Details
			</h2>
			<table class="form-table">
				<tr>
					<th scope="row" class="align-right" width="100">
						<?php echo $form->labelEx($user, 'username'); ?>
					</th>
					<td>
						<?php echo $user->username; ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right" width="100">
						<?php echo $form->labelEx($user, 'license_no', array('label' => 'CEA License No.')); ?>
					</th>
					<td>
						<?php echo $user->license_no; ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right">
						<?php echo $form->labelEx($user, 'name'); ?>
					</th>
					<td>
						<?php echo $form->textField($user, 'name', array('size' => 45, 'maxlength' => 255)); ?>
						<?php echo $form->error($user, 'name'); ?>
						<p class="hint no-margin">
							Name that appears in forms, documents and listings.
						</p>
					</td>
				</tr>

				<tr>
					<th scope="row" class="align-right">
						<?php echo $form->labelEx($user, 'display_name'); ?>
					</th>
					<td>
						<?php echo $form->textField($user, 'display_name', array('size' => 30, 'maxlength' => 255)); ?>
						<?php echo $form->error($user, 'display_name'); ?>
						<p class="hint no-margin">
							Name that appears in your public profile, SMS adverts, etc.
						</p>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right">
						<?php echo $form->labelEx($user, 'nric', array('label' => 'NRIC')); ?>
					</th>
					<td>
						<?php echo $form->textField($user, 'nric', array('size' => 12, 'maxlength' => 30)); ?>
						<?php echo $form->error($user, 'nric'); ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right">
						<?php echo $form->labelEx($user, 'agency_id', array('label' => 'Agency')); ?>
					</th>
					<td>
						<div class="input-field">
							<?php
							echo $form->textField($user->agency, 'name', array(
								'size' => 40,
								'disabled' => true
							));
							?>
							<?php echo $form->error($user->agency, 'name'); ?>
						</div>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right" width="100">
						<?php echo $form->labelEx($user, 'agency_team_id', array('label' => 'Team:')); ?>
					</th>
					<td>
						<div class="form-table-block">
							<?php echo $form->dropDownList($user, 'agency_team_id', CHtml::listData(AgencyTeam::model()->ofCurrentAgency()->findAll(array('order' => 't.name ASC')), 'id', 'name'), array('prompt' => '(none)')); ?>
							<?php echo $form->error($user, 'agency_team_id'); ?>
						</div>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right">
						<?php echo $form->labelEx($user, 'photo'); ?>
					</th>
					<td>
						<?php if ($user->photo): ?>
							<div id="agent-photo-preview">
								<img src="<?php echo $user->photo; ?>" />
								<a id="remove-photo" href="<?php echo $this->createUrl('users/update', array('id' => $user->id, 'action' => 'RemoveImage')); ?>">Remove</a>
							</div>
						<?php else: ?>
							<?php echo $form->fileField($user, 'photo'); ?>
							<?php echo $form->error($user, 'photo'); ?>
						<?php endif; ?>
					</td>
				</tr>
				<tr>
					<th scope="row" width="150" class="align-right">
						<?php echo $form->labelEx($user, 'timezone'); ?>
					</th>
					<td>
						<?php echo $form->dropDownList($user, 'timezone', User::getTimezoneListData()); ?>
					</td>
				</tr>
				<?php if (Yii::app()->user->checkModuleAccess('Propsage.Vendor')): ?>
					<tr>
						<th scope="row" width="150">
							<?php echo $form->labelEx($user, 'vendor_id', array('label' => 'Vendor')); ?>
						</th>
						<td>
							<?php
							$this->widget('common.widgets.PsSelect2.PsSelect2', array(
								'model' => $user,
								'attribute' => 'vendor_id',
								'data' => Yii::app()->user->model->agency->getVendorsListData(),
								'htmlOptions' => array(
									'prompt' => '',
									'multiple' => false,
									'style' => 'width:300px;',
									'data-placeholder' => 'Select vendor'
								)
							));
							?>
							<?php echo $form->error($user, 'vendor_id'); ?>
							<p class="hint">Select this if this user is a vendor account. For normal salespersons & agency accounts, leave this option blank.</p>
						</td>
					</tr>
				<?php endif; ?>
			</table>
		</div>
	</div>
	<div class="section">
		<div class="block">
			<h2>
				<img src="/images/icons/farmfresh/32x32/book.png" />
				Profile Information
			</h2>
			<table class="form-table">
				<tr>
					<th scope="row" class="align-right" width="150">
						<?php echo $form->labelEx($user, 'license_expiry_date'); ?>
					</th>
					<td>							
						<?php
						$form->widget('PsJuiDatePicker', array(
							'model' => $user,
							'attribute' => 'license_expiry_date',
							'options' => array(
								'showButtonPanel' => false,
								'changeYear' => true,
								'changeMonth' => true,
								'dateFormat' => 'dd-mm-yy',
							),
						));
						?>
						<?php echo $form->error($user, 'license_expiry_date'); ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right" width="150">
						<?php echo $form->labelEx($user, 'license_fee_deduction_date', array('label' => 'License Fee Deduction')); ?>
					</th>
					<td>							
						<?php
						$form->widget('PsJuiDatePicker', array(
							'model' => $user,
							'attribute' => 'license_fee_deduction_date',
							'options' => array(
								'showButtonPanel' => false,
								'changeYear' => true,
								'changeMonth' => true,
								'yearRange' => 'c-100:c+0',
								'dateFormat' => 'dd-mm-yy',
							),
						));
						?>
						<?php echo $form->error($user, 'license_fee_deduction_date'); ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right" width="150">
						<?php echo $form->labelEx($user, 'join_date'); ?>
					</th>
					<td>							
						<?php
						$form->widget('PsJuiDatePicker', array(
							'model' => $user,
							'attribute' => 'join_date',
							'options' => array(
								'showButtonPanel' => false,
								'changeYear' => true,
								'changeMonth' => true,
								'yearRange' => 'c-100:c+0',
								'dateFormat' => 'dd-mm-yy',
							),
						));
						?>
						<?php echo $form->error($user, 'join_date'); ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right" width="150">
						<?php echo $form->labelEx($user, 'left_date'); ?>
					</th>
					<td>							
						<?php
						$form->widget('PsJuiDatePicker', array(
							'model' => $user,
							'attribute' => 'left_date',
							'options' => array(
								'showButtonPanel' => false,
								'changeYear' => true,
								'changeMonth' => true,
								'yearRange' => 'c-100:c+0',
								'dateFormat' => 'dd-mm-yy',
							),
						));
						?>
						<?php echo $form->error($user, 'left_date'); ?>
					</td>
				</tr>
				
			</table>
		</div>
	</div>
	<div class="section">
		<div class="block">
			<h2>
				<img src="/images/icons/farmfresh/32x32/phone_vintage.png" />
				Contact Information	
			</h2>
			<table class="form-table">					
				<tr>
					<th scope="row" class="align-right" width="100">
						<label>Email:</label>
					</th>
					<td>
						<?php echo $form->textField($user, 'email', array('size' => 40, 'maxlength' => 50)); ?>
						<?php echo $form->error($user, 'email'); ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right">
						<?php echo $form->labelEx($user, 'mobile'); ?>
					</th>
					<td>
						<?php echo $form->textField($user, 'mobile', array('size' => 20, 'maxlength' => 30)); ?>
						<?php echo $form->error($user, 'mobile'); ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right">
						<?php echo $form->labelEx($user, 'landline'); ?>
					</th>
					<td>
						<?php echo $form->textField($user, 'landline', array('size' => 20, 'maxlength' => 30)); ?>
						<?php echo $form->error($user, 'landline'); ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right">
						Mailing Address
					</th>
					<td>
						<div class="form-table-block">
							<?php echo $form->labelEx($user, 'block'); ?>
							<?php echo $form->textField($user, 'block', array('size' => 8)); ?>
							<?php echo $form->error($user, 'block'); ?>
						</div>
						<div class="form-table-block">
							<?php echo $form->labelEx($user, 'street'); ?>
							<?php echo $form->textField($user, 'street', array('size' => 39)); ?>
							<?php echo $form->error($user, 'street'); ?>
						</div>
						<div class="form-table-block">
							<?php echo $form->labelEx($user, 'floor'); ?>
							<?php echo $form->textField($user, 'floor', array('size' => 4)); ?>
							<?php echo $form->error($user, 'floor'); ?>
						</div>
						<div class="form-table-block">
							<?php echo $form->labelEx($user, 'unit'); ?>
							<?php echo $form->textField($user, 'unit', array('size' => 6)); ?>
							<?php echo $form->error($user, 'unit'); ?>
						</div>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right" width="90">
					</th>
					<td>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right" width="90"></th>
					<td>
						<div class="form-table-block">
							<?php echo $form->labelEx($user, 'country_code', array('label' => 'Country')); ?>
							<?php
							echo $form->dropDownList($user, 'country_code', Country::getCountryListDataByCountryCode(), array(
								'prompt' => 'Select Country',
								'options' => array('separator1' => array('disabled' => true), 'separator2' => array('disabled' => true))
							));
							?>
							<?php echo $form->error($user, 'country_code'); ?>
						</div>
						<div class="form-table-block">
							<?php echo $form->labelEx($user, 'postcode'); ?>
							<?php echo $form->textField($user, 'postcode', array('size' => 12)); ?>
							<?php echo $form->error($user, 'postcode'); ?>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<div class="section">
		<div class="block">
			<h2>
				<img src="/images/icons/farmfresh/32x32/user.png" />
				Personal Particulars
			</h2>
			<table class="form-table">
				<tr>
					<th scope="row" class="align-right" width="100">
						<?php echo $form->labelEx($user, 'gender'); ?>
					</th>
					<td>
						<?php
						echo $form->radioButtonList($user, 'gender', User::getGenderListData(), array(
							'separator' => '&nbsp;'
						));
						?>
						<?php echo $form->error($user, 'gender'); ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right" width="100">
						<?php echo $form->labelEx($user, 'marital'); ?>
					</th>
					<td>
						<?php
						echo $form->dropDownList($user, 'marital', User::getMaritalStatusListData(), array(
							'prompt' => ''
						));
						?>
						<?php echo $form->error($user, 'marital'); ?>
					</td>
				</tr>
				<tr>
					<th scope="row" class="align-right" width="100">
						<?php echo $form->labelEx($user, 'birthday'); ?>
					</th>
					<td>							
						<?php
						$form->widget('PsJuiDatePicker', array(
							'model' => $user,
							'attribute' => 'birthday',
							'options' => array(
								'showButtonPanel' => false,
								'changeYear' => true,
								'changeMonth' => true,
								'yearRange' => 'c-100:c+0',
								'dateFormat' => 'dd-mm-yy',
							),
						));
						?>
						<?php echo $form->error($user, 'birthday'); ?>
					</td>
				</tr>
				<tr>
					<th scope="row" width="150" class="align-right">
						<?php echo $form->labelEx($user, 'nationality'); ?>
					</th>
					<td>
						<div class="form-table-block">
							<?php echo $form->dropDownList($user, 'nationality', Country::getNationalityListData(), array('prompt' => '')); ?>
							<?php echo $form->error($user, 'nationality'); ?>
						</div>
					</td>
				</tr>
				<tr>
					<th scope="row" width="150" class="align-right">
						<?php echo $form->labelEx($user, 'religion'); ?>
					</th>
					<td>
						<div class="form-table-block">
							<?php echo $form->dropDownList($user, 'religion', ReligionType::getListData(), array('prompt' => '')); ?>
							<?php echo $form->textField($user, 'religion_other', array('size' => 40, 'maxlength' => 45)); ?>
							<?php echo $form->error($user, 'religion'); ?>
						</div>
					</td>
				</tr>
				<tr>
					<th scope="row" width="150" class="align-right">
						<?php echo $form->labelEx($user, 'highest_qualification'); ?>
					</th>
					<td>
						<div class="form-table-block">
							<?php echo $form->dropDownList($user, 'highest_qualification', QualificationType::getListData(), array('prompt' => '')); ?>
							<?php echo $form->textField($user, 'highest_qualification_other', array('size' => 40, 'maxlength' => 255)); ?>
							<?php echo $form->error($user, 'highest_qualification'); ?>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<?php
	$this->renderPartial('_update_custom', array(
		'user' => $user,
		'customFields' => $customFields,
		'customFieldGroups' => $customFieldGroups,
	));
	?>
</div>
<div class="grid_6">
	<div class="section">
		<div class="block">
			<h2>Roles</h2>
			<?php if (!empty($roles)): ?>
				<?php foreach ($roles as $role): ?>
					<div>
						<label for="<?php echo CHtml::getIdByName('roles[' . $role->name . ']'); ?>">
							<?php echo CHtml::checkBox('roles[' . $role->name . ']', $authManager->isAssigned($role->name, $user->id), array('uncheckValue' => 0)); ?>
							<?php echo $role->description; ?>
						</label>
					</div>
				<?php endforeach; ?>
			<?php else: ?>
				No Roles defined.
			<?php endif; ?>
		</div>
	</div>
	<div class="section">
		<div class="block">
			<h2>
				<img src="/images/icons/farmfresh/32x32/setting_tools.png" />
				Settings
			</h2>
			<table class="form-table">
				<tr>
					<td colspan="2">
						<span class="valign-middle">
							<?php echo $form->checkBox($user, 'show_on_website'); ?>
							<?php echo $form->error($user, 'show_on_website'); ?>
							<?php echo $form->labelEx($user, 'show_on_website', array('label' => 'Show Profile on Web Portal')); ?>
						</span>
					</td>
				</tr>
			</table>
		</div>
	</div>
</div>
<div class="grid_16">
	<div class="row buttons">
		<div class="cell">
			<?php echo CHtml::submitButton('Save Changes', array('name' => 'ProfileSave', 'class' => 'no-margin green')); ?>
		</div>
		<br/>
	</div>
</div>
<?php $this->endWidget(); ?>